//
//  DrawLineViewController.m
//  OCAnimation
//
//  Created by zhouLiHuan on 2017/2/17.
//  Copyright © 2017年 zhouLiHuan. All rights reserved.
//

#import "DrawLineViewController.h"

@interface DrawLineViewController ()

@end

@implementation DrawLineViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    UIView *tempView = [[UIView alloc]initWithFrame:CGRectMake(50, 100, 250, 500)];
    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:tempView.frame];
    
    //椭圆线条
    CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
    shapeLayer.strokeColor = [UIColor purpleColor].CGColor; //线条颜色
    shapeLayer.fillColor = [UIColor clearColor].CGColor; //实习渲染颜色
    shapeLayer.lineWidth = 2.0f;  //线宽
    shapeLayer.lineJoin = kCALineJoinRound; //设置线条转角的样式
    shapeLayer.lineCap = kCALineCapRound; //设置线条起点和终点的样式
    shapeLayer.path = bezierPath.CGPath;
    [self.view.layer addSublayer:shapeLayer];
    
    //动画
    CABasicAnimation *pathAnim = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    pathAnim.duration = 5.0f;
    pathAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pathAnim.fromValue = @(0);
    pathAnim.toValue = @(1);
    pathAnim.autoreverses = YES;
    pathAnim.fillMode = kCAFillModeForwards;
    pathAnim.repeatCount = HUGE_VALF;
    [shapeLayer addAnimation:pathAnim forKey:@"strokeEndAnim"];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
